#include<stdio.h>
#include<string.h>
int main()
{
    char year[5];
    int num,jiange=0;
    int i,j;
    scanf("%s %d",year,&num);
    if(strlen(year)<4)
    {
            for(i=0;i<strlen(year);i++)
            {
                year[3-i]=year[strlen(year)-i-1];
            }
            while(3-i>=0)
            {
                year[3-i]='0';
                i++;
            }
    }
    while(1)
    {
        int ls=0;
        int s[10]={0};
        for(i=0;i<4;i++)
            for(j=i;j<4;j++)
            {
                if(year[i]==year[j])
                s[year[i]-'0']++;
            }
        for(i=0;i<10;i++)
            if(s[i]!=0)
                ls++;
        if(ls==num)
        {
            printf("%d %s",jiange,year);
            break;
        }
        jiange++;
        year[3]++;
        for(i=0;i<4;i++)
            if(year[3-i]=='9'+1)
            {
                year[3-i]='0';
                year[2-i]++;
            }
    }
    return 0;
}